Questions tagged [records]

Active record models (or “records”) are models, with a database-facing layer built in.

Filter by
Sorted by
Tagged with
0
votes
0answers
10 views

Nested Relationship

With PHP, how do we query a relationship of a relationship using Active Record? We are not directly querying the relation (venue) with the relationship (city). I've tried $model = $model->...
2
votes
1answer
16 views

What do multiple columns of a record being set to unique mean?

Does the following mean that both columns or the combination of columns needs to be unique? public function defineIndexes() { return [ ['columns' => ['productId', 'productTypeId'], '...
0
votes
1answer
231 views

How many users can Craft handle?

I'm looking to use a Craft3 installation as a bridge app to synch a client's contacts from their CRM server to their Email Service Provider, via respective APIs. I'll be storing their contacts as ...
1
vote
1answer
70 views

Best way to handle large amount of records

What is the best way to handle 20,000 simple records? The records need to be searchable and linked to categories. What is the best way to handle so many records when each records or entry would be a ...
2
votes
1answer
134 views

Paginate records?

I'm creating a custom plugin for customer reviews on products. In the CP I have an interface to view and aprove these. What I am wondering is if it is any easy way to paginate my records? Right now ...
1
vote
1answer
176 views

Saving Form Data to Plugin Record via Javascript

I am new to Craft plugin development, so I apologize ahead of time for my lack of understanding. I'm working on a plugin that allows the user to "upload" Excel/csv files via the control panel that ...
2
votes
0answers
512 views

Custom plugin - cannot save record

I have a service which am passing a model and an identifier (optional) to. The model contains new data and the aim is that if an existing record exists then we merge the two responses into a ...
1
vote
1answer
145 views

AttributeType::Handle Validation and Unique

I'm building a plugin that has a column in the DB which is unique and essentially an AttributeType::Handle. Here is the piece from the record: return array( 'key' => array(AttributeType::...
0
votes
1answer
211 views

Update record definition after plugin is already installed

If you have a plugin installed with its own tables and you want to add some extra database fields to the table, what is the process for this? Craft will create database tables using records on ...
1
vote
0answers
43 views

Filter conditions on related UserModel in custom Record

My plugin has a custom ResponseRecord with relations to a UserRecord and ElementRecord as follows: public function defineRelations() { return array( 'user' => array(static::BELONGS_TO,...
4
votes
2answers
140 views

How do I include record relationships in validation?

Say I have a record defining a foreign key relationship which is set to required, such as: public function defineRelations() { return [ 'type' => [ static::BELONGS_TO, ...
2
votes
1answer
385 views

Getting related models in templates?

I recently started learning plugin development for Craft CMS. I'm creating a plugin that deals with video content. For this example I'll use two models: MyPlugin_ChannelModel and MyPlugin_VideoModel. ...
4
votes
1answer
290 views

Foreign Key column pointing to `craft_relations` table

I am writing a plugin with a Record. I want the primary key of the table to also be a foreign key relating to the craft_relations table. Ordinarily, I would add something like this... public function ...
4
votes
1answer
152 views

How can I populate some records after my plugin is installed?

When I install the plugin, I need to automatically create a few records. How can I have my plugin automatically create those records when it is installed?
3
votes
1answer
761 views

Model/Record AttributeType documentation?

I'm building a plugin which creates a few tables, and need to store some fairly robust data. I've done this before and previously gotten by with mostly AttributeType::String and AttributeType::Mixed, ...
2
votes
2answers
163 views

Is it possible to create composite Primary Keys in Records?

I've structured my Record as such: <?php namespace Craft; class MyPlugin_MerchantOrderRecord extends BaseRecord { public function getTableName() { return 'myplugin_merchant_orders'; } ...
1
vote
1answer
166 views

Add Record without deleting data

I'm working on a plugin, and would like to add a new Record, I already have some records, and would like to keep the data. Is there a way to activate a new record type, without re-installing the ...
2
votes
1answer
208 views

Save multiple records at once

I would like to be able to save multiple records at once. What is the best way of doing this? I can of course iterate over my records and use the save function for each one. However, this is not very ...
1
vote
1answer
63 views

Define record start ID

Is there a way to define my plugins Record start ID? Now it start with ID 1, and for various reasons I would like to define a starting number.
0
votes
1answer
361 views

Plugin Use Default Value When Empty

I've got a default value defined in my model for a field 'limit' => array(AttributeType::Number, 'default' => 0) When I create a new record, if the limit field is empty, NULL gets stored in ...
0
votes
1answer
83 views

Unable to connect to db via console with a custom config directory path

I've just used yiic for the first time for a plugin record installation and found that the db.php config file didn't seem to be picked up and I got database connection failures. I added a console ...
3
votes
2answers
111 views

Plugin uninstall only removes one table

When uninstalling my plugin, only one table is removed. Two others are left behind. Any suggestions what I'm doing wrong? Could it be naming with and without the underscore? The good: <?php ...
0
votes
1answer
83 views

Hooking into event when record deleted from custom plugin

We are using a plugin that has created its own record for storing private messages. When deleting a message, it's calling the delete() method on an instance of the record, which appears to be using ...
2
votes
1answer
618 views

Dealing with existing data in a separate database

I'm creating a site with Craft that needs to communicate with an existing database, which is separate from the database Craft will be installed on. My client is already using an existing online ...
2
votes
1answer
1k views

Craft CMS Plugin Save Record to DB from Variable

I am tearing my hair out with this! So, I have a variable file setup as follows <?php namespace Craft; class TrackrVariable { public function startTrace() { if(!isset($_COOKIE['...
2
votes
1answer
100 views

Mysql error when defining related tables

I'm trying to create some relational tables from 2 records but I keep getting the mysql error: CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1005 Can't create table ...
2
votes
1answer
241 views

How to create plugin pivot table entries?

I have a record for an entity my plugin needs and that may be related to many Entries, so I have a pivot table, much like Craft's usergroups_user table. I'm creating and updating my table fine and I'...
5
votes
1answer
772 views

What attribute type should I set in the record or model to create a TEXT type in the database?

I am having a problem with record and model attribute types. I have a frontend user form with some textfields which require a TEXT type field in the database to hold the data. So far I have tried ...
0
votes
1answer
658 views

setAttribute Issue

I have a controller function creating attributes for a model from posted data and sending them to a service to save the data. Everything seems to be working correctly if I do a print_r in the service ...
8
votes
1answer
1k views

Query table in a different database

I'm writing another plugin for my craft app, this time I'm attempting to reuse a MySQL table that's used by other applications as well. I've a class extending the BaseRecord, and getTableName() will ...
1
vote
0answers
142 views

Record - Mixed/String values will not be saved if attribute not required=true

I have defined string and mixed attributes for my Record/Model. 'titel' => array(AttributeType::String), 'lage' => array(AttributeType::Mixed, 'required' => true), If i try to save a record,...
1
vote
1answer
282 views

When using Active Record with a View (instead of Table) the primary key is not set in the record after save

I ran into a problem when saving a new record. I have created a test below. When saving a record using a db table, the record is saved to the db and the primary key id is updated in the record ...
0
votes
1answer
445 views

AttributeType::String is NULL in my database

I have create a plugin to save information from my form in the front-end. I can create a row with some data. Email and Number type work well but String is NULL Have you any idea ? my controller ...
1
vote
1answer
394 views

Plugin: Making a record's dateUpdated column update to CURRENT_TIMESTAMP

When creating a record in a plugin it automatically creates dataCreated and dataUpdated columns. However, it doesn't look like the dataUpdated columns is updated on update. Is there a way to set ...
1
vote
1answer
222 views

The Active Record

I have a question on Craft's Active Record, protected function defineAttributes(){ 'customer_ref' => array( AttributeType::String, 'required' => true ), ...
3
votes
1answer
263 views

Can a model or record have conditional requirements?

I have a form that spans two pages, with a required field on both pages and an optional field on both pages: Form A - Page 1 - Question 1 (required) - Question 2 (optional) [User submits partial ...
3
votes
1answer
999 views

Models v Records - confused

If a Model can be used to save entries, what is a Record for? Is it literally just to define the schema? I've seen a few examples where the defineAttributes methods have duplication of code too, so I'...
5
votes
2answers
1k views

Populate a record with a model?

In a follow up to my earlier question, I'm focusing on cleaning up my code to keep it incredibly simple. I've moved on from the Controller and Model to the Model and Service. Typically you would have ...
0
votes
0answers
208 views

Complex queries

I'm wondering: what is the best way to do complex queries for a plugin? For example, I'm building a site that publishes stories and sometimes the same story can be in different languages. The ...
8
votes
2answers
2k views

How do I get model/record attributes in their proper types, and not just strings?

Here's my record (model is nearly identical): namespace Craft; class Recurly_PlanRecord extends BaseRecord { public function getTableName() { return 'recurly_plans'; } protected ...
5
votes
1answer
745 views

How can I expand on a normal Craft query to sort by a column in a custom table?

I have a plugin which contains a Record. My record contains a foreign key of the related element ID. The only other column in my custom table is the value I'd like to sort by. In Twig syntax, how can ...
2
votes
1answer
247 views

How can I join plugin data with entry data based on uri?

I have a plugin with a record (and model). The record have attributes uri and hits. The uri attribute in my record corresponds to an entry's uri, as stored in the craft_elements_i18n table. What is ...
1
vote
1answer
151 views

Do I need a model when I have a record?

I have a record so I can save my data to the DB but do I need a model for services and stuff ? Or can the record do that too ?
1
vote
1answer
164 views

Plugin: Fill Record with data (auto generated form)

Is there a way to generate a form based on my record-attributes ? Like a quick and dirty CRUD-Interface to get started ? And otherwise: where would I create such forms ? Are those Controllers ?
3
votes
1answer
444 views

How to check if a DateTime attribute is set?

I have a optional dateFinished attribute in my Record: protected function defineAttributes() { return array( ... 'dateFinished' => AttributeType::DateTime, ... ); }...