Laravel access to relation in WHEN [duplicate] - mysql

This question already has answers here:
Laravel - Eloquent "Has", "With", "WhereHas" - What do they mean?
(2 answers)
Closed 3 months ago.
Hello guys i need to implement filtering result for Document model. My document model have relation with Customer and i need to filter that results with searching multiple columns in customer relation (name and address). I try with traditional way $document->customerRelation->name, customer.name and isn't working.
So i have HTML table with prited documents and there is also printed customer name and customer address. When i type in text box some keywords like (jon or test) i need to filter that columns.
Document
Customer
Address
Document Type
00213
Jon
Test
Inovice
00214
Thomas
Test
Proforma
00215
Agly
Test
Guaranty
00216
Adams
Test
User manual
Here is code
public function index(Request $request)
{
$documents =
Document::when(
$request->has('document_tip_id'), function ($q) use ($request) {
return $q->where('document_tip_id', $request->query('document_tip_id'));
}) // this working
// Here i need to filter by relation (customer.name or address and other columns)
->when(
$request->has('keywords'), function ($q) use ($request) {
return $q->where('customer.name', '%'.$request->query('customer') . '%');
})
->with('products')
->with('customer')
->orderBy('created_at');
$documents = $documents->paginate(20)->withQueryString();
dd($documents);
return ....
}
Dump
Illuminate\Pagination\LengthAwarePaginator {#408 ▼ // app/Http/Controllers/Order/BuyerController.php:38
#items: Illuminate\Database\Eloquent\Collection {#346 ▼
#items: array:20 [▼
0 => App\Models\Document {#321 ▼
#connection: "mysql"
#table: "dokument"
#primaryKey: "id"
#keyType: "int"
#observables: []
#relations: array:2 [▼
"product" => Illuminate\Database\Eloquent\Collection {#343 ▶}
"customer" => App\Models\Customer {#432 ▼
#connection: "mysql"
#table: "customer"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:28 [▼
"id" => 975
"code" => "123"
"name" => "Jon Don"
"address" => "Test address"
"created_at" => "2020-11-05 21:55:46"
"updated_at" => "2020-11-05 21:55:46"
"deleted_at" => null
]
Model
// Customer.php
public function customer()
{
return $this->belongsTo(Customer::class, 'subjekat_id');
}
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customer.name'
in 'where clause'

Problem is sloved using whereReklation
->when(
$request->has('keywords'),
function ($q) use ($request) {
return $q->whereRelation('customer', 'name', 'LIKE', '%'.$request->query('keywords') . '%');
})

Related

Getting error while using GroupBy and Pagination in Eloquent

I'm trying to use eloquent to get me a grouped by response and at the same time give me a Pagination response (The one that gives me the link to the second page).
I'm trying to do this:
App\Eating::Where('student_id', 2)->orderBy('created_at', 'DESC')->groupBy(function ($row) {
return Carbon\Carbon::parse($row->created_at)->format('Y-m-d');
})->paginate(25);
But, I'm getting this error when running it in the Tinker:
PHP warning: strtolower() expects parameter 1 to be string, object given in D:\Folder\vendor\laravel\framework\src\Illuminate\Database\Grammar.php on line 58
without the groupBy, I'm getting the correct result:
>>> App\Eating::Where('student_id', 2)->orderBy('created_at', 'DESC')->paginate(25)->toArray();
=> [
"total" => 1,
"per_page" => 25,
"current_page" => 1,
"last_page" => 1,
"next_page_url" => null,
"prev_page_url" => null,
"from" => 1,
"to" => 3,
"data" => [
[
"id" => 5,
"status" => "Comeu Bem",
"created_at" => "2017-07-05 13:55:25",
"updated_at" => "2017-07-05 13:55:25",
],
],
]
BUT, when I remove the pagination, I do get the error but only because I added the get():
>>> App\Eating::Where('student_id', 2)->orderBy('created_at', 'DESC')->groupBy(function ($row) {
... return Carbon\Carbon::parse($row->created_at)->format('Y-m-d');
... })->get();
PHP warning: strtolower() expects parameter 1 to be string, object given in D:\Joao\git\F1Softwares\Code\Server\F1Softwares\vendor\laravel\framework\src\Illuminate\Database\Grammar.php on line 58
>>>
>>>
>>> App\Eating::Where('student_id', 2)->orderBy('created_at', 'DESC')->groupBy(function ($row) {
... return Carbon\Carbon::parse($row->created_at)->format('Y-m-d');
... });
=> Illuminate\Database\Eloquent\Builder {#855}
Any idea what I could be doing wrong? I do need to have the orderBy AND the pagination, to make it easier for the app to show the results(It is a RestFul call).
Thanks,
João
You must call the groupBy() method on a collection, but it seems this won't work with paginate(). You could try using the forPage() method on the collection:
App\Eating::where('student_id', 2)->orderBy('created_at', 'DESC')
->get()->groupBy(function ($eating) {
return $eating->created_at->format('Y-m-d');
})->forPage(1, 25);
Also, just a note, you don't need to use Carbon to parse the date, Eloquent does this for you.
Alternatively, you could try to manually create your paginator once you have the collection grouped using Illuminate\Pagination\LengthAwarePaginator.
$eatings = App\Eating::where('student_id', 2)->orderBy('created_at', 'DESC')
->get()->groupBy(function ($eating) {
return $eating->created_at->format('Y-m-d');
});
$paginatedEatings = new LengthAwarePaginator($eatings, $eatings->count(), 25);
return $paginatedEatings->toArray();

how to write mysql AND/OR in cakephp find() method [duplicate]

This question already has answers here:
cakephp OR condition
(4 answers)
Closed 6 years ago.
I wanted to find out a way to write the following code into cakephp find() method but the didn't find related resource on the cakebook.
my code is
SELECT * FROM Customers
WHERE
(Country='Germany' AND City='München')
OR (Country='Germany' AND CustomerName='München');
please share a way to write this accordingly in find() method. Thanks
You can do this using the OR key when using where:
$query = $this->Customers
->find()
->where([
'OR' => [
[
'City' => 'München',
'Country' => 'Germany'
],
[
'Country' => 'Germany',
'CustomerName' => 'München'
]
]
]);
This could be simplified to:
$query = $this->Customers
->find()
->where([
'Country' => 'Germany',
'OR' => [
['City' => 'München'],
['CustomerName' => 'München']
]
]);
See http://book.cakephp.org/3.0/en/orm/query-builder.html#advanced-conditions, I find using the andWhere and orWhere functions in combination so just stick to where!
Try
$query = $this->Customers->find(
'all',
[
'conditions' => [
'Country' => 'Germany',
'OR' => [
[
'City' => 'München',
],
[
'CustomerName' => 'München'
]
]
]
]
);
In the cookbook it says to wrap the or conditions in arrays if they are pertaining to the same field http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#complex-find-conditions
If you want to paginate results you can try this:
public function yourFunctionName() {
$this->paginate['conditions']['and'][] = ['Country' => 'Germany'];
$this->paginate['conditions']['and']['or'][] = ['City' => 'München'];
$this->paginate['conditions']['and']['or'][] = ['CustomerName' => 'München'];
$customers = $this->paginate($this->Customers);
$this->set(compact('customers'));
$this->set('_serialize', ['customers']);
}

Datatables not sorting date correctly Serverside

I am using server side processing, so as I understand, all sorting/ordering is done server side. However, when I click on the column header, it should send the server a post variable to apply the ASC or DESC sort order. This is not working and I'm trying to figure out where my problem lies.
I am using the default script that comes with datatables.
My dates in the database is stored as timestamp values such as 15-10-2015 10:20:30.
Now, the table displays fine, however the dates are not sorted correctly. Even if I output just the year values e.g. 2014 , it does not sort them ASC and DESC.
Instead, I get results like:
2014
2014
2015
2015
2014
2014
2015
:(
I declare the table as follows :
DemoTable = $('#table_demo').DataTable(
{
"order": [],
"aaSorting" : [],
"deferRender": true,
"bJQueryUI": true,
"bPaginate": true,
"bStateSave": true,
"processing": true,
"serverSide": true,
"sPaginationType": "full_numbers",
"ajax":
{
"url": "view_demo_remote.php",
"data":
{
"role": $_SESSION['role'],
"email": $_SESSION['email'],
"practiseid": $_SESSION['practiceid']
}
},
"columns":[
{ "data": "first_number" , "bSortable": true },
{ "data": "datecreated", "bSortable": true },
{ "data": "submitted_by"},
{ "data": "second_number"},
{ "data": "picture","bSortable": false },
{ "data": "options","bSortable": false }
],
});
On the server, I have the following section for the columns:
$columns = array(
array(
'db' => 'id',
'dt' => 'DT_RowId',
'formatter' => function( $d, $row )
{
// Technically a DOM id cannot start with an integer, so we prefix
// a string. This can also be useful if you have multiple tables
// to ensure that the id is unique with a different prefix
return $d;
}
),
array(
'db' => 'firstnumber',
'dt' => 'first_number',
'formatter' => function($d, $row)
{
$number = $d;
return substr($number, 0, 10);
}),
array(
'db' => 'datecreated',
'dt' => 'datecreated',
'formatter' => function($d, $row)
{
// DD/MM/YYYY HH:MM:SS
$date = date_create_from_format('d-m-Y H:i:s', $d);
return date_format($date, 'Y');
}),
array( 'db' => 'username', 'dt' => 'submitted_by' ),
array( 'db' => 'secondnumber', 'dt' => 'second_number' ),
array(
'db' => 'picture',
'dt' => 'picture',
'formatter' => function($d, $row)
{
return "<p style=\"padding:5px;\"><img src=\"".$d."\" alt=\"Picture\" style=\"width:auto;max-height:70px;border:1px solid #2d2d2d;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px; \"></img></p>";
}),
array( 'db' => 'id', 'dt' => 'options');
);
and then I have this part after the columns section:
// SQL server connection information
$sql_details = array(
'user' => DBUSER,
'pass' => DBUSERPASS,
'db' => DBNAME,
'host' => DBHOST
);
require( 'libraries/DataTables-1.10.7/examples/server_side/scripts/ssp.class.php' );
$whereAll = " firstnumber <>''";
echo json_encode(SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, "",$whereAll));
So the table displays fine, all column headers for the sortable columns can be clicked on and it sorts ASC or DESC perfectly. However, the date does not sort perfectly. If I turn off sorting off on the table and I manually add "ORDER BY datecreated ASC" to the where clause, it works perfectly, which tells me that there is nothing wrong with my date format, however, I want sorting ON.
Please help
I have also asked a question on the datatables forums https://www.datatables.net/forums/discussion/31216/datatables-not-ordering-date-correctly
Thanks all for contributing.
At the end of the day, the problem was actually caused by a field in the database that was in the wrong format. The datecreated field was saved as a Varchar and it had to be DATETIME.
Once I fixed this in the database, everything sorted perfectly.
thanks for everyone who helped. But yes, I want to stress the fact that when server side processing is being done, all sorting / ordering is done server side. You can manipulate the format and display on the client side, but NOT the actual order, when server side is being used.

How to parse this JSON object/string?

I am trying to parse the JSON written # http://a0.awsstatic.com/pricing/1/ec2/sles-od.min.js
Here is a quick snippet from above link:
{vers:0.01,config:{rate:"perhr",valueColumns:["vCPU","ECU","memoryGiB","storageGB","sles"],currencies:["USD"],regions:[{region:"us-east",instanceTypes:[{type:"generalCurrentGen",sizes:[{size:"t2.micro",vCPU:"1",ECU:"variable",
...
...
...
...
Please visit the aforementioned link to see the complete JSON.
As seen above, none of the keys of above JSON have Double Quotes around them.
This leads to malformed JSON string and my JSON parser is failing at it. I also tried putting this JSON in http://www.jsoneditoronline.org/ and it fails as well.
Now, this is the same link which is used by Amazon to display various prices of their EC2 instance. So I think I am missing something here. My Googling led me to believe that above thing is not JSON and is instead JSONP.. I don't understand what is that.
Could you help me understand how to parse this JSON. BTW, I am doing this work in perl using JSON Module.
Some background:
Amazon Web Services does not have an API to get Pricing info programmatically. Hence I am parsing these links which is what amazon is doing while displaying pricing information here. Besides, I am not from programming space and perl is all I know.
Like you said JSONP or "JSON with padding" can't be parsed by json parser because it is not json (it is a different format). But it is actually a json with the prefix (padding)
The padding is typically the name of a callback function that wraps json.
In this case, its default callback names 'callback' and we can do a bit hackiest way by using Regular Expression to capture json that is wrapped by 'callback()' like this
s/callback\((.*)\);$/$1/s;
Also, if you would like to use JSON library, you can enable allow_barekey which means you don't need those quotes around those keys.
Below is my working code. I use LWP::Simple to get the content for the given and Data::Dump to print the isolated data structure.
use strict;
use warnings;
use LWP::Simple;
use JSON;
my $jsonp = get("http://a0.awsstatic.com/pricing/1/ec2/sles-od.min.js")
or die "Couldn't get url";
( my $json = $jsonp ) =~ s/callback\((.*)\);$/$1/s; #grap the json from $jsonp and store in $json variable
my $hash = JSON->new->allow_barekey->decode ( $json );
use Data::Dump;
dd $hash;
Outputs:
{
config => {
currencies => ["USD"],
rate => "perhr",
regions => [
{
instanceTypes => [
{
sizes => [
{
ECU => "variable",
memoryGiB => 1,
size => "t2.micro",
storageGB => "ebsonly",
valueColumns => [{ name => "os", prices => { USD => 0.023 } }],
vCPU => 1,
},
{
ECU => "variable",
memoryGiB => 2,
size => "t2.small",
storageGB => "ebsonly",
valueColumns => [{ name => "os", prices => { USD => 0.056 } }],
vCPU => 1,
},
{
ECU => "variable",
memoryGiB => 4,
size => "t2.medium",
storageGB => "ebsonly",
valueColumns => [{ name => "os", prices => { USD => 0.152 } }],
vCPU => 2,
},
{
ECU => 3,
memoryGiB => 3.75,
size => "m3.medium",
storageGB => "1 x 4 SSD",
valueColumns => [{ name => "os", prices => { USD => "0.170" } }],
vCPU => 1,
},
....
As said in comments above, it is not JSON so it can't be parsed by JSON parser... But for an quick & (very)dirty work, you can try the JSON::DWIW module.
The next code:
use 5.014;
use warnings;
use WWW::Mechanize;
use Data::Dump;
use JSON::DWIW;
my $mech = WWW::Mechanize->new();
my $jsonstr = $mech->get('http://a0.awsstatic.com/pricing/1/ec2/sles-od.min.js')->content;
($jsonstr) = $jsonstr =~ /callback\((.*)\)/s;
my $json_obj = JSON::DWIW->new;
my $data = $json_obj->from_json( $jsonstr );
dd $data;
prints a structure what maybe is what you want, e.g.:
{
config => {
currencies => ["USD"],
rate => "perhr",
regions => [
{
instanceTypes => [
{
sizes => [
{
ECU => "variable",
memoryGiB => 1,
size => "t2.micro",
storageGB => "ebsonly",
valueColumns => [{ name => "os", prices => { USD => 0.023 } }],
vCPU => 1,
},
{

How to extract nested hashes into database table?

I am trying to extract some data that is being returned in a nested hash from Mailchimp. Here is a trimmed down version of the results I am getting. For each email there are multiple GROUPINGS and for each GROUPING there are multiple GROUPS.
My objective is to get this into a mysql table with a layout like: email_addr, list, grouping1_id, grouping1_name, group1_name, group1_interest, group2_name, group2_interest, grouping2_id, grouping2_name, etc. So there is one row per subscriber with all the grouping and group information.
{"email"=>"dummy#gmail.com", "merges"=>{"EMAIL"=>"dummy#gmail.com",
"GROUPINGS"=>[{"id"=>1, "name"=>"Grouping One", "groups"=>[{"name"=>"Group One",
"interested"=>false}, {"name"=>"Group", "interested"=>true},
{"name"=>"Group Three", "interested"=>true}]}, {"id"=>2, "name"=>"Grouping Two",
"groups"=>[{"name"=>"Group Four", "interested"=>false},
{"name"=>"Group Five", "interested"=>false}]}]}}
Right now, the code I have below runs and inserts the results of the nested blocks into the table but there is one row for each pass through the groups.each_with_index statement. My approach so far seems overly complicated but I am not sure of how to approach this to process the data correctly.
Any help is appreciated.
UPDATED:
I cleaned up the logic a bit and separated the database writes into each level of the hash processing. Now the data is inserted and updated in the database correctly. Although this still feels very inelegant.
def organize_members_subs
#members_data = #members_subs["data"]
#members_data.each do |member|
#email_addr = member["email"]
#db.query("INSERT INTO db.details
(email_addr, list)
VALUES ('#{#email_addr}', '#{#list}' ) ")
groupings = member["merges"]["GROUPINGS"]
groupings.each_with_index do |grouping, index|
#groupings_name = grouping["name"]
#groupings_id = grouping["id"]
#groupings_label = "grp#{index}_"
#db.query("UPDATE db.details
SET grouping#{index}_id = '#{#groupings_id}'
, grouping#{index}_name = '#{#groupings_name}'
WHERE email_addr = '#{#email_addr}' ")
groups = member["merges"]["GROUPINGS"][index]["groups"]
groups.each_with_index do |group, index|
#group_name = group["name"]
#group_interested = group["interested"]
#db.query("UPDATE db.details
SET #{#groupings_label}group#{index}_name = '#{#group_name}'
, #{#groupings_label}group#{index}_int = '#{#group_interested}'
WHERE email_addr = '#{#email_addr}' ")
break if index == groups.length
end
break if index == groupings.length
end
end
end
To start, I wanted to take a closer at look your hash. Rather than reformatting it myself, I did this:
require "awesome_print"
h = `{"email"=>..., "interested"=>false}]}]}}`
ap h
Scroll down to the bottom of my answer to see ap's formatting of the hash.
I will answer your question assuming the db structure is a given, but would like to make a few points:
If "id" is unique for each grouping record, could you make that the key, and dispense with index?
If "name" is unique for each grouping record, could you dispense with both "id" and index?
If "name" is unique for each group record (for a given grouping), could you just have group["name"] => group["interested"] for each group?
Moving on to your code, I will also assume the structure of your hash is given. Later, I will revisit that assumption.
The changes I propose to your code are fairly minor and some are purely stylistic:
Make all instance variables local variables, meaning that two additional arguments must be passed to def organize_members_subs.
With two possible exceptions, eliminate local variables that are only used once after being defined. For example, rather than
groupings_id = grouping["id"], then SET grouping#{index}_id = '#{#groupings_id}', just have SET grouping#{index}_id = '#{grouping["id"]}'.
The two possible exceptions are groupings and groups. For example, you could get rid of the former by writing
member["merges"]["GROUPINGS"].each_with_index do |grouping, index_1|. I'd keep them as variables (so I could easily check their values),
but that's a stylistic decision.
The variable index in groupings.each_with_index do |grouping, index| is in scope within the inner block, which uses an iterator variable with the same name.
I presume that the latter takes precedence, but they should be named differently. I've changed them to index_out and index_in, respectively.
index_out ranges from 0 to groupings.length-1, so break if index_out == groupings.length will never be executed, and therefore may be removed. Ditto for break if index_in == groups.length.
I moved groupings_label = "grp#{index}_" down to draw attention to the fact that it is needed only later, not in the preceding SET expression.
These changes result in the following:
def organize_members_subs(db, list, #members_subs["data"])
members_data.each do |member|
email_addr = member["email"]
db.query("INSERT INTO db.details
(email_addr, list)
VALUES ('#{email_addr}', '#{list}' ) ")
groupings = member["merges"]["GROUPINGS"]
groupings.each_with_index do |grouping, index_out|
db.query("UPDATE db.details
SET grouping#{index_out}_id = '#{grouping["id"]}'
, grouping#{index_out}_name = '#{grouping["name"]}'
WHERE email_addr = '#{email_addr}' ")
groupings_label = "grp#{index_out}_"
groups = member["merges"]["GROUPINGS"][index_out]["groups"]
groups.each_with_index do |group, index_in|
db.query("UPDATE db.details
SET #{groupings_label}group#{index_in}_name = '#{group["name"]}'
, #{groupings_label}group#{index_in}_int = '#{group["interested"]}'
WHERE email_addr = '#{email_addr}' ")
end
end
end
end
Looking at your hash, I am wondering if you could simplify it to the following (formatting courtesy of awesome print):
{
"email" => "dummy#gmail.com",
"merges" => {
"EMAIL" => "dummy#gmail.com",
"GROUPINGS" => {
1 => {
"name" => "Grouping One",
"groups" => {
"Group One" => false,
"Group Two" => true,
"Group Three" => true
}
},
2 => {
"name" => "Grouping Two",
"groups" => {
"Group Four" => false,
"Group Five" => false
}
}
}
}
}
or even
{
"email" => "dummy#gmail.com",
"merges" => {
"EMAIL" => "dummy#gmail.com",
"GROUPINGS" => {
"Grouping One" => {
"Group One" => false,
"Group Two" => true,
"Group Three" => true
},
"Grouping Two" => {
"Group Four" => false,
"Group Five" => false
}
}
}
}
These are not so much as suggestions, but just food for thought.
Awesome print applied to your hash:
ap h # =>
{
"email" => "dummy#gmail.com",
"merges" => {
"EMAIL" => "dummy#gmail.com",
"GROUPINGS" => [
[0] {
"id" => 1,
"name" => "Grouping One",
"groups" => [
[0] {
"name" => "Group One",
"interested" => false
},
[1] {
"name" => "Group",
"interested" => true
},
[2] {
"name" => "Group Three",
"interested" => true
}
]
},
[1] {
"id" => 2,
"name" => "Grouping Two",
"groups" => [
[0] {
"name" => "Group Four",
"interested" => false
},
[1] {
"name" => "Group Five",
"interested" => false
}
]
}
]
}
}
First, maybe extra, but I like to work with symbols since I do a lot of my work in Rails. So let's steal a method from here: How do I convert a Ruby hash so that all of its keys are symbols?
def recursive_symbolize_keys(h)
case h
when Hash
Hash[
h.map do |k, v|
[ k.respond_to?(:to_sym) ? k.to_sym : k, recursive_symbolize_keys(v) ]
end
]
when Enumerable
h.map { |v| recursive_symbolize_keys(v) }
else
h
end
end
OK, lets build a class to make this easier to manipulate and extend as our needs change:
class MemberSub
attr_accessor :email, :groupings, :data_hash, :list, :data_row, :db_sql
def initialize(data_hash)
#convert all keys to symbols
#data_hash = recursive_symbolize_keys(data_hash)
#email = #data_hash[:email]
#list = 'Members'
#groupings = #data_hash[:merges][:GROUPINGS]
#data_row = data_row
#db_sql = db_insert
end
def data_row
#returns a data row for DB
row_hash = {}
row_hash['email'] = #email
row_hash['list'] = #list
gc = 1
#iterate through groupings
#groupings.each_with_index do |grouping, index|
row_hash["grouping#{index + 1}_id"] = grouping[:id]
row_hash["grouping#{index + 1}_name"] = grouping[:name]
#iterate through the groups
grouping[:groups].each do |group|
row_hash["group#{gc}_name"] = group[:name]
row_hash["group#{gc}_interest"] = group[:interested]
gc += 1
end
end
row_hash
end
def db_insert
"INSERT INTO db.details (#{#data_row.keys}) VALUES (#{#data_row.values})".tr('[]','')
end
end
Now you can do feed it a row using what ever iteration method and make a new object:
row = MemberSub.new({"email"=>"dummy#gmail.com", "list"=>"Members", "merges"=>
{"EMAIL"=>"dummy#gmail.com", "GROUPINGS"=>[{"id"=>1, "name"=>"Grouping One", "groups"=>
[{"name"=>"Group One", "interested"=>false}, {"name"=>"Group Two", "interested"=>true},
{"name"=>"Group Three", "interested"=>true}]}, {"id"=>2, "name"=>"Grouping Two", "groups"=>
[{"name"=>"Group Four", "interested"=>false}, {"name"=>"Group Five", "interested"=>false}]}]}})
and make a query:
db.query(row.db_sql)
db.query(INSERT INTO db.details ("email", "list", "grouping1_id", "grouping1_name",
"group1_name", "group1_interest", "group2_name", "group2_interest", "group3_name",
"group3_interest", "grouping2_id", "grouping2_name", "group4_name", "group4_interest",
"group5_name", "group5_interest") VALUES ("dummy#gmail.com", "Members", 1, "Grouping One",
"Group One", false, "Group Two", true, "Group Three", true, 2, "Grouping Two", "Group Four",
false, "Group Five", false))
The other methods should be self explanatory. You don't have to have them all available as attar_accessor but I just did that for example.